home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perlrun.Z / perlrun
Encoding:
Text File  |  1998-10-28  |  37.8 KB  |  1,057 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perlrun - how    to execute the Perl interpreter
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       ppppeeeerrrrllll [ ----ssssTTTTuuuuUUUU ]      [    ----hhhhvvvv ] [    ----VVVV[:_c_o_n_f_i_g_v_a_r] ]
  13.            [ ----ccccwwww ] [ ----dddd[:_d_e_b_u_g_g_e_r] ] [ ----DDDD[_n_u_m_b_e_r/_l_i_s_t] ]
  14.            [ ----ppppnnnnaaaa ]    [ ----FFFF_p_a_t_t_e_r_n ] [    ----llll[_o_c_t_a_l] ] [ ----0000[_o_c_t_a_l]    ]
  15.            [ ----IIII_d_i_r ] [ ----mmmm[----]_m_o_d_u_l_e ] [ ----MMMM[----]'_m_o_d_u_l_e...' ]
  16.            [ ----PPPP ]       [ ----SSSS    ]      [ ----xxxx[_d_i_r] ]
  17.            [ ----iiii[_e_x_t_e_n_s_i_o_n] ]      [    ----eeee '_c_o_m_m_a_n_d' ] [ --------
  18.        ] [ _p_r_o_g_r_a_m_f_i_l_e ] [ _a_r_g_u_m_e_n_t    ]...
  19.  
  20.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  21.       Upon startup,    Perl looks for your script in one of the
  22.       following places:
  23.  
  24.       1.  Specified    line by    line via ----eeee switches on    the command
  25.           line.
  26.  
  27.       2.  Contained    in the file specified by the first filename on
  28.           the command line.     (Note that systems supporting the #!
  29.           notation invoke interpreters this    way. See the section
  30.           on _L_o_c_a_t_i_o_n _o_f _P_e_r_l.)
  31.  
  32.       3.  Passed in    implicitly via standard    input.    This works
  33.           only if there are    no filename arguments--to pass
  34.           arguments    to a STDIN script you must explicitly specify
  35.           a    "-" for    the script name.
  36.  
  37.       With methods 2 and 3,    Perl starts parsing the    input file
  38.       from the beginning, unless you've specified a    ----xxxx switch, in
  39.       which    case it    scans for the first line starting with #! and
  40.       containing the word "perl", and starts there instead.     This
  41.       is useful for    running    a script embedded in a larger message.
  42.       (In this case    you would indicate the end of the script using
  43.       the __END__ token.)
  44.  
  45.       The #! line is always    examined for switches as the line is
  46.       being    parsed.     Thus, if you're on a machine that allows only
  47.       one argument with the    #! line, or worse, doesn't even
  48.       recognize the    #! line, you still can get consistent switch
  49.       behavior regardless of how Perl was invoked, even if ----xxxx was
  50.       used to find the beginning of    the script.
  51.  
  52.       Because many operating systems silently chop off kernel
  53.       interpretation of the    #! line    after 32 characters, some
  54.       switches may be passed in on the command line, and some may
  55.       not; you could even get a "-"    without    its letter, if you're
  56.       not careful.    You probably want to make sure that all    your
  57.       switches fall    either before or after that 32 character
  58.       boundary.  Most switches don't actually care if they're
  59.       processed redundantly, but getting a - instead of a complete
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  71.  
  72.  
  73.  
  74.       switch could cause Perl to try to execute standard input
  75.       instead of your script.  And a partial ----IIII switch could also
  76.       cause    odd results.
  77.  
  78.       Some switches    do care    if they    are processed twice, for
  79.       instance combinations    of ----llll and ----0000.  Either put all the
  80.       switches after the 32    character boundary (if applicable), or
  81.       replace the use of ----0000_d_i_g_i_t_s by BEGIN{    $/ = "\0digits"; }.
  82.  
  83.       Parsing of the #! switches starts wherever "perl" is
  84.       mentioned in the line.  The sequences    "-*" and "- " are
  85.       specifically ignored so that you could, if you were so
  86.       inclined, say
  87.  
  88.           #!/bin/sh    -- # -*- perl -*- -p
  89.           eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
  90.           if $running_under_some_shell;
  91.  
  92.       to let Perl see the ----pppp switch.
  93.  
  94.       If the #! line does not contain the word "perl", the program
  95.       named    after the #! is    executed instead of the    Perl
  96.       interpreter.    This is    slightly bizarre, but it helps people
  97.       on machines that don't do #!,    because    they can tell a
  98.       program that their SHELL is /usr/bin/perl, and Perl will
  99.       then dispatch    the program to the correct interpreter for
  100.       them.
  101.  
  102.       After    locating your script, Perl compiles the    entire script
  103.       to an    internal form.    If there are any compilation errors,
  104.       execution of the script is not attempted.  (This is unlike
  105.       the typical shell script, which might    run part-way through
  106.       before finding a syntax error.)
  107.  
  108.       If the script    is syntactically correct, it is    executed.  If
  109.       the script runs off the end without hitting an _e_x_i_t()    or
  110.       _d_i_e()    operator, an implicit exit(0) is provided to indicate
  111.       successful completion.
  112.  
  113.       ####!!!! aaaannnndddd qqqquuuuoooottttiiiinnnngggg oooonnnn nnnnoooonnnn----UUUUnnnniiiixxxx ssssyyyysssstttteeeemmmmssss
  114.  
  115.       Unix's #! technique can be simulated on other    systems:
  116.  
  117.       OS/2
  118.           Put
  119.  
  120.           extproc perl -S -your_switches
  121.  
  122.           as the first line    in *.cmd file (-S due to a bug in
  123.           cmd.exe's    `extproc' handling).
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  137.  
  138.  
  139.  
  140.       MS-DOS
  141.           Create a batch file to run your script, and codify it in
  142.           ALTERNATIVE_SHEBANG (see the _d_o_s_i_s_h._h file in the    source
  143.           distribution for more information).
  144.  
  145.       Win95/NT
  146.           The Win95/NT installation, when using the    Activeware
  147.           port of Perl, will modify    the Registry to    associate the
  148.           ._p_l extension with the perl interpreter.    If you install
  149.           another port of Perl, including the one in the Win32
  150.           directory    of the Perl distribution, then you'll have to
  151.           modify the Registry yourself.  Note that this means you
  152.           can no longer tell the difference    between    an executable
  153.           Perl program and a Perl library file.
  154.  
  155.       Macintosh
  156.           Macintosh    perl scripts will have the appropriate Creator
  157.           and Type,    so that    double-clicking    them will invoke the
  158.           perl application.
  159.  
  160.       Command-interpreters on non-Unix systems have    rather
  161.       different ideas on quoting than Unix shells.    You'll need to
  162.       learn    the special characters in your command-interpreter (*,
  163.       \ and    " are common) and how to protect whitespace and    these
  164.       characters to    run one-liners (see -e below).
  165.  
  166.       On some systems, you may have    to change single-quotes    to
  167.       double ones, which you must _N_O_T do on    Unix or    Plan9 systems.
  168.       You might also have to change    a single % to a    %%.
  169.  
  170.       For example:
  171.  
  172.           #    Unix
  173.           perl -e 'print "Hello world\n"'
  174.  
  175.           #    MS-DOS,    etc.
  176.           perl -e "print \"Hello world\n\""
  177.  
  178.           #    Macintosh
  179.           print "Hello world\n"
  180.            (then Run "Myscript" or Shift-Command-R)
  181.  
  182.           #    VMS
  183.           perl -e "print ""Hello world\n"""
  184.  
  185.       The problem is that none of this is reliable:    it depends on
  186.       the command and it is    entirely possible neither works.  If
  187.       4DOS was the command shell, this would probably work better:
  188.  
  189.           perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
  190.  
  191.       CMD.EXE in Windows NT    slipped    a lot of standard Unix
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  203.  
  204.  
  205.  
  206.       functionality    in when    nobody was looking, but    just try to
  207.       find documentation for its quoting rules.
  208.  
  209.       Under    the Macintosh, it depends which    environment you    are
  210.       using.  The MacPerl shell, or    MPW, is    much like Unix shells
  211.       in its support for several quoting variants, except that it
  212.       makes    free use of the    Macintosh's non-ASCII characters as
  213.       control characters.
  214.  
  215.       There    is no general solution to all of this.    It's just a
  216.       mess.
  217.  
  218.       LLLLooooccccaaaattttiiiioooonnnn ooooffff PPPPeeeerrrrllll
  219.  
  220.       It may seem obvious to say, but Perl is useful only when
  221.       users    can easily find    it. When possible, it's    good for both
  222.       ////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll    and ////uuuussssrrrr////llllooooccccaaaallll////bbbbiiiinnnn////ppppeeeerrrrllll    to be symlinks to the
  223.       actual binary. If that can't be done,    system administrators
  224.       are strongly encouraged to put (symlinks to) perl and    its
  225.       accompanying utilities, such as perldoc, into    a directory
  226.       typically found along    a user's PATH, or in another obvious
  227.       and convenient place.
  228.  
  229.       In this documentation, #!/usr/bin/perl on the    first line of
  230.       the script will stand    in for whatever    method works on    your
  231.       system.
  232.  
  233.       SSSSwwwwiiiittttcccchhhheeeessss
  234.  
  235.       A single-character switch may    be combined with the following
  236.       switch, if any.
  237.  
  238.           #!/usr/bin/perl -spi.bak      # same as -s -p -i.bak
  239.  
  240.       Switches include:
  241.  
  242.       ----0000[_d_i_g_i_t_s]
  243.            specifies the input record separator ($/) as an octal
  244.            number.    If there are no    digits,    the null character is
  245.            the separator.  Other switches may precede or follow
  246.            the digits.  For    example, if you    have a version of ffffiiiinnnndddd
  247.            which can print filenames terminated by the null
  248.            character, you can say this:
  249.  
  250.            find    . -name    '*.bak'    -print0    | perl -n0e unlink
  251.  
  252.            The special value 00 will cause Perl to slurp files in
  253.            paragraph mode.    The value 0777 will cause Perl to
  254.            slurp files whole because there is no legal character
  255.            with that value.
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  269.  
  270.  
  271.  
  272.       ----aaaa   turns on    autosplit mode when used with a    ----nnnn or ----pppp.  An
  273.            implicit    split command to the @F    array is done as the
  274.            first thing inside the implicit while loop produced by
  275.            the ----nnnn or ----pppp.
  276.  
  277.            perl    -ane 'print pop(@F), "\n";'
  278.  
  279.            is equivalent to
  280.  
  281.            while (<>) {
  282.                @F = split(' ');
  283.                print pop(@F), "\n";
  284.            }
  285.  
  286.            An alternate delimiter may be specified using ----FFFF.
  287.  
  288.       ----cccc   causes Perl to check the    syntax of the script and then
  289.            exit without executing it.  Actually, it    _w_i_l_l execute
  290.            BEGIN, END, and use blocks, because these are
  291.            considered as occurring outside the execution of    your
  292.            program.
  293.  
  294.       ----dddd   runs the    script under the Perl debugger.     See the
  295.            _p_e_r_l_d_e_b_u_g manpage.
  296.  
  297.       ----dddd::::_f_o_o
  298.            runs the    script under the control of a debugging    or
  299.            tracing module installed    as Devel::foo. E.g., ----dddd::::DDDDPPPPrrrrooooffff
  300.            executes    the script using the Devel::DProf profiler.
  301.            See the _p_e_r_l_d_e_b_u_g manpage.
  302.  
  303.       ----DDDD_l_e_t_t_e_r_s
  304.  
  305.       ----DDDD_n_u_m_b_e_r
  306.            sets debugging flags.  To watch how it executes your
  307.            script, use ----DDDDttttllllssss.  (This works only if debugging is
  308.            compiled    into your Perl.)  Another nice value is    ----DDDDxxxx,
  309.            which lists your    compiled syntax    tree.  And ----DDDDrrrr
  310.            displays    compiled regular expressions. As an
  311.            alternative, specify a number instead of    list of
  312.            letters (e.g., ----DDDD11114444 is equivalent to ----DDDDttttllllssss):
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  335.  
  336.  
  337.  
  338.                1  p  Tokenizing    and parsing
  339.                2  s  Stack snapshots
  340.                4  l  Context (loop) stack processing
  341.                8  t  Trace execution
  342.               16  o  Method and    overloading resolution
  343.               32  c  String/numeric conversions
  344.               64  P  Print preprocessor    command    for -P
  345.              128  m  Memory allocation
  346.              256  f  Format processing
  347.              512  r  Regular expression    parsing    and execution
  348.             1024  x  Syntax tree dump
  349.             2048  u  Tainting checks
  350.             4096  L  Memory leaks (needs C<-DLEAKTEST> when compiling Perl)
  351.             8192  H  Hash dump -- usurps values()
  352.            16384  X  Scratchpad    allocation
  353.            32768  D  Cleaning up
  354.            65536  S  Thread synchronization
  355.  
  356.            All these flags require -DDEBUGGING when    you compile
  357.            the Perl    executable.  This flag is automatically    set if
  358.            you include -g option when Configure asks you about
  359.            optimizer/debugger flags.
  360.  
  361.       ----eeee _c_o_m_m_a_n_d_l_i_n_e
  362.            may be used to enter one    line of    script.     If ----eeee is
  363.            given, Perl will    not look for a script filename in the
  364.            argument    list.  Multiple    ----eeee commands may    be given to
  365.            build up    a multi-line script.  Make sure    to use
  366.            semicolons where    you would in a normal program.
  367.  
  368.       ----FFFF_p_a_t_t_e_r_n
  369.            specifies the pattern to    split on if ----aaaa is also in
  370.            effect.    The pattern may    be surrounded by //, "", or
  371.            '', otherwise it    will be    put in single quotes.
  372.  
  373.       ----hhhh   prints a    summary    of the options.
  374.  
  375.       ----iiii[_e_x_t_e_n_s_i_o_n]
  376.            specifies that files processed by the <>    construct are
  377.            to be edited in-place.  It does this by renaming    the
  378.            input file, opening the output file by the original
  379.            name, and selecting that    output file as the default for
  380.            _p_r_i_n_t() statements.  The    extension, if supplied,    is
  381.            used to modify the name of the old file to make a
  382.            backup copy, following these rules:
  383.  
  384.            If no extension is supplied, no backup is made and the
  385.            current file is overwritten.
  386.  
  387.            If the extension    doesn't    contain    a * then it is
  388.            appended    to the end of the current filename as a
  389.            suffix.
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  401.  
  402.  
  403.  
  404.            If the extension    does contain one or more * characters,
  405.            then each * is replaced with the    current    filename.  In
  406.            perl terms you could think of this as:
  407.  
  408.            ($backup = $extension) =~ s/\*/$file_name/g;
  409.  
  410.            This allows you to add a    prefix to the backup file,
  411.            instead of (or in addition to) a    suffix:
  412.  
  413.            $ perl -pi'bak_*' -e    's/bar/baz/' fileA     # backup    to 'bak_fileA'
  414.  
  415.            Or even to place    backup copies of the original files
  416.            into another directory (provided    the directory already
  417.            exists):
  418.  
  419.            $ perl -pi'old/*.bak' -e 's/bar/baz/' fileA # backup    to 'old/fileA.bak'
  420.  
  421.            These sets of one-liners    are equivalent:
  422.  
  423.            $ perl -pi -e 's/bar/baz/' fileA           # overwrite current file
  424.            $ perl -pi'*' -e 's/bar/baz/' fileA           # overwrite current file
  425.  
  426.            $ perl -pi'.bak' -e 's/bar/baz/' fileA      # backup    to 'fileA.bak'
  427.            $ perl -pi'*.bak' -e    's/bar/baz/' fileA     # backup    to 'fileA.bak'
  428.  
  429.            From the    shell, saying
  430.  
  431.            $ perl -p -i.bak -e "s/foo/bar/; ...    "
  432.  
  433.            is the same as using the    script:
  434.  
  435.            #!/usr/bin/perl -pi.bak
  436.            s/foo/bar/;
  437.  
  438.            which is    equivalent to
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  467.  
  468.  
  469.  
  470.            #!/usr/bin/perl
  471.            $extension =    '.bak';
  472.            while (<>) {
  473.                if ($ARGV ne $oldargv) {
  474.                if ($extension !~ /\*/) {
  475.                    $backup = $ARGV . $extension;
  476.                }
  477.                else    {
  478.                    ($backup    = $extension) =~ s/\*/$ARGV/g;
  479.                }
  480.                rename($ARGV, $backup);
  481.                open(ARGVOUT, ">$ARGV");
  482.                select(ARGVOUT);
  483.                $oldargv = $ARGV;
  484.                }
  485.                s/foo/bar/;
  486.            }
  487.            continue {
  488.                print;  # this prints to    original filename
  489.            }
  490.            select(STDOUT);
  491.  
  492.            except that the ----iiii form doesn't need to compare $ARGV
  493.            to $oldargv to know when    the filename has changed.  It
  494.            does, however, use ARGVOUT for the selected filehandle.
  495.            Note that STDOUT    is restored as the default output
  496.            filehandle after    the loop.
  497.  
  498.            As shown    above, Perl creates the    backup file whether or
  499.            not any output is actually changed.  So this is just a
  500.            fancy way to copy files:
  501.  
  502.            $ perl -p -i'/some/file/path/*' -e 1    file1 file2 file3...
  503.          or
  504.            $ perl -p -i'.bak' -e 1 file1 file2 file3...
  505.  
  506.            You can use eof without parentheses to locate the end
  507.            of each input file, in case you want to append to each
  508.            file, or    reset line numbering (see example in the eof
  509.            entry in    the _p_e_r_l_f_u_n_c manpage).
  510.  
  511.            If, for a given file, Perl is unable to create the
  512.            backup file as specified    in the extension then it will
  513.            skip that file and continue on with the next one    (if it
  514.            exists).
  515.  
  516.            For a discussion    of issues surrounding file permissions
  517.            and -i, see the section on _W_h_y _d_o_e_s _P_e_r_l    _l_e_t _m_e _d_e_l_e_t_e
  518.            _r_e_a_d-_o_n_l_y _f_i_l_e_s?     _W_h_y _d_o_e_s -_i _c_l_o_b_b_e_r _p_r_o_t_e_c_t_e_d _f_i_l_e_s?
  519.            _I_s_n'_t _t_h_i_s _a _b_u_g    _i_n _P_e_r_l? in the    _p_e_r_l_f_a_q_5 manpage.
  520.  
  521.            You cannot use ----iiii to create directories or to strip
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  533.  
  534.  
  535.  
  536.            extensions from files.
  537.  
  538.            Perl does not expand ~, so don't    do that.
  539.  
  540.            Finally,    note that the ----iiii switch    does not impede
  541.            execution when no files are given on the    command    line.
  542.            In this case, no    backup is made (the original file
  543.            cannot, of course, be determined) and processing
  544.            proceeds    from STDIN to STDOUT as    might be expected.
  545.  
  546.       ----IIII_d_i_r_e_c_t_o_r_y
  547.            Directories specified by    ----IIII are prepended to the    search
  548.            path for    modules    (@INC),    and also tells the C
  549.            preprocessor where to search for    include    files.    The C
  550.            preprocessor is invoked with ----PPPP;    by default it searches
  551.            /usr/include and    /usr/lib/perl.
  552.  
  553.       ----llll[_o_c_t_n_u_m]
  554.            enables automatic line-ending processing.  It has two
  555.            effects:     first,    it automatically chomps    "$/" (the
  556.            input record separator) when used with ----nnnn or ----pppp,    and
  557.            second, it assigns "$\" (the output record separator)
  558.            to have the value of _o_c_t_n_u_m so that any print
  559.            statements will have that separator added back on.  If
  560.            _o_c_t_n_u_m is omitted, sets "$\" to the current value of
  561.            "$/".  For instance, to trim lines to 80    columns:
  562.  
  563.            perl    -lpe 'substr($_, 80) = ""'
  564.  
  565.            Note that the assignment    $\ = $/    is done    when the
  566.            switch is processed, so the input record    separator can
  567.            be different than the output record separator if    the ----llll
  568.            switch is followed by a ----0000 switch:
  569.  
  570.            gnufind / -print0 | perl -ln0e 'print "found    $_" if -p'
  571.  
  572.            This sets $\ to newline and then    sets $/    to the null
  573.            character.
  574.  
  575.       ----mmmm[----]_m_o_d_u_l_e
  576.  
  577.       ----MMMM[----]_m_o_d_u_l_e
  578.  
  579.       ----MMMM[----]'_m_o_d_u_l_e ...'
  580.  
  581.       ----[[[[mmmmMMMM]]]][----]_m_o_d_u_l_e=_a_r_g[,_a_r_g]...
  582.            -m_m_o_d_u_l_e    executes use _m_o_d_u_l_e ();    before executing your
  583.            script.
  584.  
  585.            -M_m_o_d_u_l_e    executes use _m_o_d_u_l_e ; before executing your
  586.            script.    You can    use quotes to add extra    code after the
  587.            module name, e.g., -M'module qw(foo bar)'.
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  599.  
  600.  
  601.  
  602.            If the first character after the    -M or -m is a dash (-)
  603.            then the    'use' is replaced with 'no'.
  604.  
  605.            A little    builtin    syntactic sugar    means you can also say
  606.            -mmodule=foo,bar    or -Mmodule=foo,bar as a shortcut for
  607.            -M'module qw(foo    bar)'.    This avoids the    need to    use
  608.            quotes when importing symbols.  The actual code
  609.            generated by -Mmodule=foo,bar is    use module
  610.            split(/,/,q{foo,bar}).  Note that the = form removes
  611.            the distinction between -m and -M.
  612.  
  613.       ----nnnn   causes Perl to assume the following loop    around your
  614.            script, which makes it iterate over filename arguments
  615.            somewhat    like sssseeeedddd ----nnnn or aaaawwwwkkkk:
  616.  
  617.            while (<>) {
  618.                ...           # your script goes here
  619.            }
  620.  
  621.            Note that the lines are not printed by default.    See ----pppp
  622.            to have lines printed.  If a file named by an argument
  623.            cannot be opened    for some reason, Perl warns you    about
  624.            it, and moves on    to the next file.
  625.  
  626.            Here is an efficient way    to delete all files older than
  627.            a week:
  628.  
  629.            find    . -mtime +7 -print | perl -nle 'unlink;'
  630.  
  631.            This is faster than using the -exec switch of ffffiiiinnnndddd
  632.            because you don't have to start a process on every
  633.            filename    found.
  634.  
  635.            BEGIN and END blocks may    be used    to capture control
  636.            before or after the implicit loop, just as in aaaawwwwkkkk.
  637.  
  638.       ----pppp   causes Perl to assume the following loop    around your
  639.            script, which makes it iterate over filename arguments
  640.            somewhat    like sssseeeedddd:
  641.  
  642.            while (<>) {
  643.                ...           # your script goes here
  644.            } continue {
  645.                print or    die "-p    destination: $!\n";
  646.            }
  647.  
  648.            If a file named by an argument cannot be    opened for
  649.            some reason, Perl warns you about it, and moves on to
  650.            the next    file.  Note that the lines are printed
  651.            automatically.  An error    occuring during    printing is
  652.            treated as fatal.  To suppress printing use the ----nnnn
  653.            switch.    A ----pppp overrides a ----nnnn switch.
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  665.  
  666.  
  667.  
  668.            BEGIN and END blocks may    be used    to capture control
  669.            before or after the implicit loop, just as in awk.
  670.  
  671.       ----PPPP   causes your script to be    run through the    C preprocessor
  672.            before compilation by Perl.  (Because both comments and
  673.            cpp directives begin with the # character, you should
  674.            avoid starting comments with any    words recognized by
  675.            the C preprocessor such as "if",    "else",    or "define".)
  676.  
  677.       ----ssss   enables some rudimentary    switch parsing for switches on
  678.            the command line    after the script name but before any
  679.            filename    arguments (or before a --------).  Any switch    found
  680.            there is    removed    from @ARGV and sets the    corresponding
  681.            variable    in the Perl script.  The following script
  682.            prints "true" if    and only if the    script is invoked with
  683.            a ----xxxxyyyyzzzz switch.
  684.  
  685.            #!/usr/bin/perl -s
  686.            if ($xyz) { print "true\n"; }
  687.  
  688.  
  689.       ----SSSS   makes Perl use the PATH environment variable to search
  690.            for the script (unless the name of the script contains
  691.            directory separators).  On some platforms, this also
  692.            makes Perl append suffixes to the filename while
  693.            searching for it.  For example, on Win32    platforms, the
  694.            ".bat" and ".cmd" suffixes are appended if a lookup for
  695.            the original name fails,    and if the name    does not
  696.            already end in one of those suffixes.  If your Perl was
  697.            compiled    with DEBUGGING turned on, using    the -Dp    switch
  698.            to Perl shows how the search progresses.
  699.  
  700.            If the filename supplied    contains directory separators
  701.            (i.e. it    is an absolute or relative pathname), and if
  702.            the file    is not found, platforms    that append file
  703.            extensions will do so and try to    look for the file with
  704.            those extensions    added, one by one.
  705.  
  706.            On DOS-like platforms, if the script does not contain
  707.            directory separators, it    will first be searched for in
  708.            the current directory before being searched for on the
  709.            PATH.  On Unix platforms, the script will be searched
  710.            for strictly on the PATH.
  711.  
  712.            Typically this is used to emulate #! startup on
  713.            platforms that don't support #!.     This example works on
  714.            many platforms that have    a shell    compatible with    Bourne
  715.            shell:
  716.  
  717.            #!/usr/bin/perl
  718.            eval    'exec /usr/bin/perl -wS    $0 ${1+"$@"}'
  719.                if $running_under_some_shell;
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  731.  
  732.  
  733.  
  734.            The system ignores the first line and feeds the script
  735.            to /bin/sh, which proceeds to try to execute the    Perl
  736.            script as a shell script.  The shell executes the
  737.            second line as a    normal shell command, and thus starts
  738.            up the Perl interpreter.     On some systems $0 doesn't
  739.            always contain the full pathname, so the    ----SSSS tells Perl
  740.            to search for the script    if necessary.  After Perl
  741.            locates the script, it parses the lines and ignores
  742.            them because the    variable $running_under_some_shell is
  743.            never true. If the script will be interpreted by    csh,
  744.            you will    need to    replace    ${1+"$@"} with $*, even    though
  745.            that doesn't understand embedded    spaces (and such) in
  746.            the argument list.  To start up sh rather than csh,
  747.            some systems may    have to    replace    the #! line with a
  748.            line containing just a colon, which will    be politely
  749.            ignored by Perl.     Other systems can't control that, and
  750.            need a totally devious construct    that will work under
  751.            any of csh, sh, or Perl,    such as    the following:
  752.  
  753.                eval '(exit $?0)' && eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
  754.                & eval 'exec /usr/bin/perl -wS $0 $argv:q'
  755.                    if $running_under_some_shell;
  756.  
  757.  
  758.       ----TTTT   forces "taint" checks to    be turned on so    you can    test
  759.            them.  Ordinarily these checks are done only when
  760.            running setuid or setgid.  It's a good idea to turn
  761.            them on explicitly for programs run on another's
  762.            behalf, such as CGI programs.  See the _p_e_r_l_s_e_c manpage.
  763.            Note that (for security reasons)    this option must be
  764.            seen by Perl quite early; usually this means it must
  765.            appear early on the command line    or in the #! line (for
  766.            systems which support that).
  767.  
  768.       ----uuuu   causes Perl to dump core    after compiling    your script.
  769.            You can then in theory take this    core dump and turn it
  770.            into an executable file by using    the uuuunnnndddduuuummmmpppp program
  771.            (not supplied).    This speeds startup at the expense of
  772.            some disk space (which you can minimize by stripping
  773.            the executable).     (Still, a "hello world" executable
  774.            comes out to about 200K on my machine.)    If you want to
  775.            execute a portion of your script    before dumping,    use
  776.            the _d_u_m_p() operator instead.  Note: availability    of
  777.            uuuunnnndddduuuummmmpppp is platform specific and may not be available
  778.            for a specific port of Perl.  It    has been superseded by
  779.            the new perl-to-C compiler, which is more portable,
  780.            even though it's    still only considered beta.
  781.  
  782.       ----UUUU   allows Perl to do unsafe    operations.  Currently the
  783.            only "unsafe" operations    are the    unlinking of
  784.            directories while running as superuser, and running
  785.            setuid programs with fatal taint    checks turned into
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  797.  
  798.  
  799.  
  800.            warnings. Note that the ----wwww switch (or the $^W variable)
  801.            must be used along with this option to actually
  802.            ggggeeeennnneeeerrrraaaatttteeee    the taint-check    warnings.
  803.  
  804.       ----vvvv   prints the version and patchlevel of your Perl
  805.            executable.
  806.  
  807.       ----VVVV   prints summary of the major perl    configuration values
  808.            and the current value of    @INC.
  809.  
  810.       ----VVVV::::_n_a_m_e
  811.            Prints to STDOUT    the value of the named configuration
  812.            variable.
  813.  
  814.       ----wwww   prints warnings about variable names that are mentioned
  815.            only once, and scalar variables that are    used before
  816.            being set.  Also    warns about redefined subroutines, and
  817.            references to undefined filehandles or filehandles
  818.            opened read-only    that you are attempting    to write on.
  819.            Also warns you if you use values    as a number that
  820.            doesn't look like numbers, using    an array as though it
  821.            were a scalar, if your subroutines recurse more than
  822.            100 deep, and innumerable other things.
  823.  
  824.            You can disable specific    warnings using __WARN__    hooks,
  825.            as described in the _p_e_r_l_v_a_r manpage and the warn    entry
  826.            in the _p_e_r_l_f_u_n_c manpage.    See also the _p_e_r_l_d_i_a_g manpage
  827.            and the _p_e_r_l_t_r_a_p    manpage.
  828.  
  829.       ----xxxx _d_i_r_e_c_t_o_r_y
  830.            tells Perl that the script is embedded in a message.
  831.            Leading garbage will be discarded until the first line
  832.            that starts with    #! and contains    the string "perl".
  833.            Any meaningful switches on that line will be applied.
  834.            If a directory name is specified, Perl will switch to
  835.            that directory before running the script.  The ----xxxx
  836.            switch controls only the    disposal of leading garbage.
  837.            The script must be terminated with __END__ if there is
  838.            trailing    garbage    to be ignored (the script can process
  839.            any or all of the trailing garbage via the DATA
  840.            filehandle if desired).
  841.  
  842.      EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT
  843.       HOME          Used if chdir has    no argument.
  844.  
  845.       LOGDIR      Used if chdir has    no argument and    HOME is    not
  846.               set.
  847.  
  848.       PATH          Used in executing    subprocesses, and in finding
  849.               the script if ----SSSS is used.
  850.  
  851.  
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  863.  
  864.  
  865.  
  866.       PERL5LIB    A    colon-separated    list of    directories in which
  867.               to look for Perl library files before looking in
  868.               the standard library and the current directory.
  869.               If PERL5LIB is not defined, PERLLIB is used.
  870.               When running taint checks    (because the script
  871.               was running setuid or setgid, or the ----TTTT switch
  872.               was used), neither variable is used.  The    script
  873.               should instead say
  874.  
  875.               use lib "/my/directory";
  876.  
  877.  
  878.       PERL5OPT    Command-line options (switches).    Switches in
  879.               this variable are    taken as if they were on every
  880.               Perl command line.  Only the ----[[[[DDDDIIIIMMMMUUUUddddmmmmwwww]]]] switches
  881.               are allowed.  When running taint checks (because
  882.               the script was running setuid or setgid, or the
  883.               ----TTTT switch    was used), this    variable is ignored.
  884.  
  885.       PERLLIB     A    colon-separated    list of    directories in which
  886.               to look for Perl library files before looking in
  887.               the standard library and the current directory.
  888.               If PERL5LIB is defined, PERLLIB is not used.
  889.  
  890.       PERL5DB     The command used to load the debugger code.  The
  891.               default is:
  892.  
  893.                   BEGIN { require 'perl5db.pl' }
  894.  
  895.  
  896.       PERL5SHELL (specific to WIN32    port)
  897.               May be set to an alternative shell that perl
  898.               must use internally for executing    "backtick"
  899.               commands or _s_y_s_t_e_m().  Default is    cmd.exe    /x/c
  900.               on WindowsNT and command.com /c on Windows95.
  901.               The value    is considered to be space delimited.
  902.               Precede any character that needs to be protected
  903.               (like a space or backslash) with a backslash.
  904.  
  905.               Note that    Perl doesn't use COMSPEC for this
  906.               purpose because COMSPEC has a high degree    of
  907.               variability among    users, leading to portability
  908.               concerns.     Besides, perl can use a shell that
  909.               may not be fit for interactive use, and setting
  910.               COMSPEC to such a    shell may interfere with the
  911.               proper functioning of other programs (which
  912.               usually look in COMSPEC to find a    shell fit for
  913.               interactive use).
  914.  
  915.       PERL_DEBUG_MSTATS
  916.               Relevant only if perl is compiled    with the
  917.               malloc included with the perl distribution (that
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  929.  
  930.  
  931.  
  932.               is, if perl -V:d_mymalloc    is 'define').  If set,
  933.               this causes memory statistics to be dumped after
  934.               execution.  If set to an integer greater than
  935.               one, also    causes memory statistics to be dumped
  936.               after compilation.
  937.  
  938.       PERL_DESTRUCT_LEVEL
  939.               Relevant only if your perl executable was    built
  940.               with ----DDDDDDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG,    this controls the behavior of
  941.               global destruction of objects and    other
  942.               references.
  943.  
  944.       Perl also has    environment variables that control how Perl
  945.       handles data specific    to particular natural languages.  See
  946.       the _p_e_r_l_l_o_c_a_l_e manpage.
  947.  
  948.       Apart    from these, Perl uses no other environment variables,
  949.       except to make them available    to the script being executed,
  950.       and to child processes.  However, scripts running setuid
  951.       would    do well    to execute the following lines before doing
  952.       anything else, just to keep people honest:
  953.  
  954.           $ENV{PATH} = '/bin:/usr/bin';    # or whatever you need
  955.           $ENV{SHELL} = '/bin/sh' if exists    $ENV{SHELL};
  956.           delete @ENV{qw(IFS CDPATH    ENV BASH_ENV)};
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))          1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        PPPPEEEERRRRLLLLRRRRUUUUNNNN((((1111))))
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.      Page 16                        (printed 10/23/98)
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.